package com.xuchao.rabbit.b8;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.xuchao.rabbit.utils.RabbitMqUtils;

import java.util.Scanner;

/**
 * @Author xuchao
 * @Date:2023/6/8 13:00
 * @description 生产者
 * @Version 1.0
 */
public class Producter {
    public static final String NORMAL_EXCHANGE = "normal_exchange";
    public static final String NORMAL_ROUTINGKEY = "zhangsan";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //死信消息 设置TTL时间 单位ms
        AMQP.BasicProperties properties = new AMQP.BasicProperties()
                .builder().expiration("10000").build();
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        for (int i = 0; i < 100; i++) {
            String message = "info:"+i;
            //1.交换机 2.队列名称 3.其他参数 4.消息体
            channel.basicPublish(NORMAL_EXCHANGE,NORMAL_ROUTINGKEY,null,message.getBytes("UTF-8"));
            System.out.println("发送完成...");
        }

    }
}
